package com.chatcompetition.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chatcompetition.domain.entity.Employee;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
    @Select("SELECT * FROM employee WHERE employee_number = #{employeeNumber} AND employee_password = #{employeePassword} AND employee_department = #{employeeDepartment}")
    Employee findByEmployeeNumberAndEmployeePasswordAndDepartment(@Param("employeeNumber") String employeeNumber, @Param("employeePassword") String employeePassword, @Param("employeeDepartment") String employeeDepartment);


    // 根据工号查询员工的 employee_status
    @Select("SELECT employee_status FROM employee WHERE employee_number = #{employeeNumber}")
    Integer findEmployeeStatusByEmployeeNumber(@Param("employeeNumber") String employeeNumber);

    @Select("SELECT id FROM employee WHERE employee_department = #{employeeDepartment}")
    Integer findEmployeeIdByEmployeeDepartment(@Param("employeeDepartment") String employeeDepartment);

    @Select("SELECT id FROM ums_role WHERE name = #{employeeDepartment}")
    Integer findRoleIdByEmployeeDepartment(@Param("employeeDepartment") String employeeDepartment);

//    @Update("UPDATE ums_admin_role_relation SET admin_id = #{adminId}, role_id = #{roleId} WHERE admin_id = #{adminId}")
//    int updateRole(@Param("adminId") Long adminId, @Param("roleId") Long roleId);
//
//    @Select("SELECT COUNT(*) FROM ums_admin_role_relation WHERE admin_id = #{adminId}")
//    int countRoleByAdminId(@Param("adminId") Long adminId);
//
//    @Insert("INSERT INTO ums_admin_role_relation (admin_id, role_id) VALUES (#{adminId}, #{roleId})")
//    int insertRole(@Param("adminId") Long adminId, @Param("roleId") Long roleId);

    @Insert("INSERT INTO ums_admin_role_relation (admin_id, role_id) VALUES (#{adminId}, #{roleId})")
    void insertRoleRelation(@Param("adminId") Long id,@Param("roleId")  Long roleId);

    @Update("UPDATE ums_admin_role_relation SET role_id = #{roleId} WHERE admin_id = #{adminId}")
    void updateRoleRelation(@Param("adminId") Long id,@Param("roleId")  Long roleId);
}